// emailObfuscator.cpp
//===========================================================================
// Programmer: Robert LaFont Jr.
// Created on: 2005.02.28
// Modified on: 2005.02.29
// Version: 1.2
// Description:
//    Encodes your email address so as to be able to be posted on a web page
//  without the risk of it being harvested by spam bots. This program 
//  encodes your email address using ASCII code characters. Following this 
//  program is a ASCII Chart of all the characters and their ASCII 
//  equivalants. The values are obtained by combining the value on the left
//  with the value on the top. (i.e. A = 65)
//===========================================================================

#include <iostream>
#include <cctype>
#include <string>
#include <fstream>
using namespace std;

int main()
{
	char again;
	string email;
	ofstream outFile;
	string fileName;
	
	cout<<"Please enter a file name and path (i.e. C:\\email.txt): "<< endl;
	cout<<"File Name: ";
	cin >> fileName;
	outFile.open(fileName.c_str());
	if(outFile.fail())
	{
		cout<<"** Error Opening "<< fileName <<" for output. **"<< endl;
		return 0;
	}
	do
	{
		cout<<"Please enter your email address: ";
		cin >> email;
		
		
		// convert all to lowercase
		for (int i = 0; i < email.length(); i++)
			email[i] = tolower(email[i]);
		
		cout<<"<a href=\"mailto:";
		
		// convert characters to there html code equivalents
		for (i = 0; i < email.length(); i++)
		{
			cout<<"&#";
			if(email[i] == 'a')
				cout<<"97";
			else if(email[i] == 'b')
				cout<<"98";
			else if(email[i] == 'c')
				cout<<"99";
			else if(email[i] == 'd')
				cout<<"100";
			else if(email[i] == 'e')
				cout<<"101";
			else if(email[i] == 'f')
				cout<<"102";
			else if(email[i] == 'g')
				cout<<"103";
			else if(email[i] == 'h')
				cout<<"104";
			else if(email[i] == 'i')
				cout<<"105";
			else if(email[i] == 'j')
				cout<<"106";
			else if(email[i] == 'k')
				cout<<"107";
			else if(email[i] == 'l')
				cout<<"108";
			else if(email[i] == 'm')
				cout<<"109";
			else if(email[i] == 'n')
				cout<<"110";
			else if(email[i] == 'o')
				cout<<"111";
			else if(email[i] == 'p')
				cout<<"112";
			else if(email[i] == 'q')
				cout<<"113";
			else if(email[i] == 'r')
				cout<<"114";
			else if(email[i] == 's')
				cout<<"115";
			else if(email[i] == 't')
				cout<<"116";
			else if(email[i] == 'u')
				cout<<"117";
			else if(email[i] == 'v')
				cout<<"118";
			else if(email[i] == 'w')
				cout<<"119";
			else if(email[i] == 'x')
				cout<<"120";
			else if(email[i] == 'y')
				cout<<"121";
			else if(email[i] == 'z')
				cout<<"122";
			else if(email[i] == '-')
				cout<<"45";
			else if(email[i] == '.')
				cout<<"46";
			else if(email[i] == '@')
				cout<<"64";
			else if(email[i] == '0')
				cout<<"48";
			else if(email[i] == '1')
				cout<<"49";
			else if(email[i] == '2')
				cout<<"50";
			else if(email[i] == '3')
				cout<<"51";
			else if(email[i] == '4')
				cout<<"52";
			else if(email[i] == '5')
				cout<<"53";
			else if(email[i] == '6')
				cout<<"54";
			else if(email[i] == '7')
				cout<<"55";
			else if(email[i] == '8')
				cout<<"56";
			else if(email[i] == '9')
				cout<<"57";
			else
				cout<<"95"; // = "_"
			cout<< "\;";
		}
		
		cout<<"\">";
		
		for (i = 0; i < email.length(); i++)
		{
			cout<<"&#";
			if(email[i] == 'a')
				cout<<"97";
			else if(email[i] == 'b')
				cout<<"98";
			else if(email[i] == 'c')
				cout<<"99";
			else if(email[i] == 'd')
				cout<<"100";
			else if(email[i] == 'e')
				cout<<"101";
			else if(email[i] == 'f')
				cout<<"102";
			else if(email[i] == 'g')
				cout<<"103";
			else if(email[i] == 'h')
				cout<<"104";
			else if(email[i] == 'i')
				cout<<"105";
			else if(email[i] == 'j')
				cout<<"106";
			else if(email[i] == 'k')
				cout<<"107";
			else if(email[i] == 'l')
				cout<<"108";
			else if(email[i] == 'm')
				cout<<"109";
			else if(email[i] == 'n')
				cout<<"110";
			else if(email[i] == 'o')
				cout<<"111";
			else if(email[i] == 'p')
				cout<<"112";
			else if(email[i] == 'q')
				cout<<"113";
			else if(email[i] == 'r')
				cout<<"114";
			else if(email[i] == 's')
				cout<<"115";
			else if(email[i] == 't')
				cout<<"116";
			else if(email[i] == 'u')
				cout<<"117";
			else if(email[i] == 'v')
				cout<<"118";
			else if(email[i] == 'w')
				cout<<"119";
			else if(email[i] == 'x')
				cout<<"120";
			else if(email[i] == 'y')
				cout<<"121";
			else if(email[i] == 'z')
				cout<<"122";
			else if(email[i] == '-')
				cout<<"45";
			else if(email[i] == '.')
				cout<<"46";
			else if(email[i] == '@')
				cout<<"64";
			else if(email[i] == '0')
				cout<<"48";
			else if(email[i] == '1')
				cout<<"49";
			else if(email[i] == '2')
				cout<<"50";
			else if(email[i] == '3')
				cout<<"51";
			else if(email[i] == '4')
				cout<<"52";
			else if(email[i] == '5')
				cout<<"53";
			else if(email[i] == '6')
				cout<<"54";
			else if(email[i] == '7')
				cout<<"55";
			else if(email[i] == '8')
				cout<<"56";
			else if(email[i] == '9')
				cout<<"57";
			else
				cout<<"95"; // = "_"
			cout<< "\;";
		}
		
		cout<<"</a>" << endl;
		
		outFile<< email << endl;
		outFile<<"<!-- Beginning -->"<< endl;
		outFile<<" <a href=\"mailto:";
		
		// convert characters to there html code equivalents
		for (i = 0; i < email.length(); i++)
		{
			outFile<<"&#";
			if(email[i] == 'a')
				outFile<<"97";
			else if(email[i] == 'b')
				outFile<<"98";
			else if(email[i] == 'c')
				outFile<<"99";
			else if(email[i] == 'd')
				outFile<<"100";
			else if(email[i] == 'e')
				outFile<<"101";
			else if(email[i] == 'f')
				outFile<<"102";
			else if(email[i] == 'g')
				outFile<<"103";
			else if(email[i] == 'h')
				outFile<<"104";
			else if(email[i] == 'i')
				outFile<<"105";
			else if(email[i] == 'j')
				outFile<<"106";
			else if(email[i] == 'k')
				outFile<<"107";
			else if(email[i] == 'l')
				outFile<<"108";
			else if(email[i] == 'm')
				outFile<<"109";
			else if(email[i] == 'n')
				outFile<<"110";
			else if(email[i] == 'o')
				outFile<<"111";
			else if(email[i] == 'p')
				outFile<<"112";
			else if(email[i] == 'q')
				outFile<<"113";
			else if(email[i] == 'r')
				outFile<<"114";
			else if(email[i] == 's')
				outFile<<"115";
			else if(email[i] == 't')
				outFile<<"116";
			else if(email[i] == 'u')
				outFile<<"117";
			else if(email[i] == 'v')
				outFile<<"118";
			else if(email[i] == 'w')
				outFile<<"119";
			else if(email[i] == 'x')
				outFile<<"120";
			else if(email[i] == 'y')
				outFile<<"121";
			else if(email[i] == 'z')
				outFile<<"122";
			else if(email[i] == '-')
				outFile<<"45";
			else if(email[i] == '.')
				outFile<<"46";
			else if(email[i] == '@')
				outFile<<"64";
			else if(email[i] == '0')
				outFile<<"48";
			else if(email[i] == '1')
				outFile<<"49";
			else if(email[i] == '2')
				outFile<<"50";
			else if(email[i] == '3')
				outFile<<"51";
			else if(email[i] == '4')
				outFile<<"52";
			else if(email[i] == '5')
				outFile<<"53";
			else if(email[i] == '6')
				outFile<<"54";
			else if(email[i] == '7')
				outFile<<"55";
			else if(email[i] == '8')
				outFile<<"56";
			else if(email[i] == '9')
				outFile<<"57";
			else
				outFile<<"95"; // = "_"
			outFile<< "\;";
		}
		
		outFile<<"\">";
		
		for (i = 0; i < email.length(); i++)
		{
			outFile<<"&#";
			if(email[i] == 'a')
				outFile<<"97";
			else if(email[i] == 'b')
				outFile<<"98";
			else if(email[i] == 'c')
				outFile<<"99";
			else if(email[i] == 'd')
				outFile<<"100";
			else if(email[i] == 'e')
				outFile<<"101";
			else if(email[i] == 'f')
				outFile<<"102";
			else if(email[i] == 'g')
				outFile<<"103";
			else if(email[i] == 'h')
				outFile<<"104";
			else if(email[i] == 'i')
				outFile<<"105";
			else if(email[i] == 'j')
				outFile<<"106";
			else if(email[i] == 'k')
				outFile<<"107";
			else if(email[i] == 'l')
				outFile<<"108";
			else if(email[i] == 'm')
				outFile<<"109";
			else if(email[i] == 'n')
				outFile<<"110";
			else if(email[i] == 'o')
				outFile<<"111";
			else if(email[i] == 'p')
				outFile<<"112";
			else if(email[i] == 'q')
				outFile<<"113";
			else if(email[i] == 'r')
				outFile<<"114";
			else if(email[i] == 's')
				outFile<<"115";
			else if(email[i] == 't')
				outFile<<"116";
			else if(email[i] == 'u')
				outFile<<"117";
			else if(email[i] == 'v')
				outFile<<"118";
			else if(email[i] == 'w')
				outFile<<"119";
			else if(email[i] == 'x')
				outFile<<"120";
			else if(email[i] == 'y')
				outFile<<"121";
			else if(email[i] == 'z')
				outFile<<"122";
			else if(email[i] == '-')
				outFile<<"45";
			else if(email[i] == '.')
				outFile<<"46";
			else if(email[i] == '@')
				outFile<<"64";
			else if(email[i] == '0')
				outFile<<"48";
			else if(email[i] == '1')
				outFile<<"49";
			else if(email[i] == '2')
				outFile<<"50";
			else if(email[i] == '3')
				outFile<<"51";
			else if(email[i] == '4')
				outFile<<"52";
			else if(email[i] == '5')
				outFile<<"53";
			else if(email[i] == '6')
				outFile<<"54";
			else if(email[i] == '7')
				outFile<<"55";
			else if(email[i] == '8')
				outFile<<"56";
			else if(email[i] == '9')
				outFile<<"57";
			else
				outFile<<"95"; // = "_"
			outFile<< "\;";
		}
		
		outFile<<"</a>" << endl;
		outFile<<"<!-- Ending -->"<< endl;
		
		cout<<"Email successfully writen to "<< fileName <<"."<< endl;
		cout<< endl;
		cout<<"Do it again? (y/n): ";
		cin >> again;
	}
	while((again == 'y') || (again == 'Y'));
	outFile.close();
	return 0;
}



/********************************************************************

	 The space character will be denoted by a " ".
	 ____________________________________________
	 | * || 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 |
	 |===||===|===|===|===|===|===|===|===|===|===|
	 | 0 ||NUL|SOH|STX|ETX|EOT|ENQ|ACK|BEL| BS| HT|
	 |---||---|---|---|---|---|---|---|---|---|---|
	 | 1 || LF| VT| FF| CR| SO| SI|DLE|DC1|DC2|DC3|
	 |---||---|---|---|---|---|---|---|---|---|---|
	 | 2 ||DC4|NAK|SYN|ETB|CAN| EM|SUB|ESC| FS| GS|
	 |---||---|---|---|---|---|---|---|---|---|---|
	 | 3 || RS| US|" "| ! | " | # | $ | % | & | ' |
	 |---||---|---|---|---|---|---|---|---|---|---|
	 | 4 || ( | ) | * | + | , | - | . | / | 0 | 1 |
	 |---||---|---|---|---|---|---|---|---|---|---|
	 | 5 || 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | : | ; |
	 |---||---|---|---|---|---|---|---|---|---|---|
	 | 6 || < | = | > | ? | @ | A | B | C | D | E |
	 |---||---|---|---|---|---|---|---|---|---|---|
	 | 7 || F | G | H | I | J | K | L | M | N | O |
	 |---||---|---|---|---|---|---|---|---|---|---|
	 | 8 || P | Q | R | S | T | U | V | W | X | Y |
	 |---||---|---|---|---|---|---|---|---|---|---|
	 | 9 || Z | [ | \ | ] | ^ | _ | ` | a | b | c |
	 |---||---|---|---|---|---|---|---|---|---|---|
	 |10 || d | e | f | g | h | i | j | k | l | m |
	 |---||---|---|---|---|---|---|---|---|---|---|
	 |11 || n | o | p | q | r | s | t | u | v | w |
	 |---||---|---|---|---|---|---|---|---|---|---|
	 |12 || x | y | z | { | | | } | ~ |DEL|   |   |
	 |---||---|---|---|---|---|---|---|---|---|---|
	 
 ********************************************************************/
